# encoding: utf-8
from flask_marshmallow import base_fields
from flask_restplus_patched import ModelSchema
from app.modules.common.schemas import BaseSchema


class ZentaoUserBaseSchema(ModelSchema):
    class Meta:
        fields = (
            'account',
            'realname',
            'role',
        )

        dump_only = (
            "account",
        )


class ZentaoProjectBaseSchema(ModelSchema):
    members = base_fields.Nested(
        ZentaoUserBaseSchema,
        many = True
    )

    class Meta:
        fields = (
            'id',
            'name',
            'begin',
            'end',
            'PM',  # 项目负责人account
            'PM_name',
            'members',
            'code',
            'isIdExist',
        )

        dump_only = (
            "name",
        )


class ProjectPlanInfoSchema(BaseSchema):
    data = base_fields.Nested(
        ZentaoProjectBaseSchema,
        many = False
    )

    class Meta:
        fields = BaseSchema.Meta.fields + (
            'data',
        )
